//
//  CropImageViewController.m
//  RainbowFM
//
//  Created by jv on 14-12-7.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "CropImageViewController.h"
#import <UIImageView+WebCache.h>
#import "UserModel.h"

@interface CropImageViewController ()

@end

@implementation CropImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    _cropper = [[ImageCropperView alloc] initWithFrame:CGRectMake(0, 64.f, self.view.width, self.view.height - 64.f)];

    __weak typeof (_cropper) _c = _cropper;
    [_cropper.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://img0.bdstatic.com/img/image/shouye/mntsc2-12893142236.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        [_c setImage:image];
    }];
    [self.view addSubview:_cropper];
    
    [self.view sendSubviewToBack:_cropper];
    
    
    self.title = @"上传头像";
}

#pragma mark - action

- (IBAction)cancelAction:(id)sender {
    [self navBackAction];
}

- (IBAction)dneAction:(id)sender {
    
    UIImage *image = [_cropper getCroppedImage];
    [[UserModel sharedModel] upLoadUserHeadImage:UIImageJPEGRepresentation(image, 0.5) result:^(BOOL success,NSString *path) {
        
    }];
    
//    if ([_delegate respondsToSelector:@selector(didSelectedImageWithCtrl:image:)]) {
//        [_delegate didSelectedImageWithCtrl:self image:image];
//    }
//    
//    [self navBackAction];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
